<template>

  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="98px">
      <el-form-item label="生产单号" prop="produceNo">
        <el-input v-model="queryParams.produceNo" placeholder="请输入生产单号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="订单编号" prop="projectNo">
        <el-input v-model="queryParams.projectNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="工序名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入工序名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="产品型号" prop="goodModel">
        <el-input v-model="queryParams.goodModel" placeholder="请输入产品型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="图纸号" prop="shuoming">
        <el-input v-model="queryParams.shuoming" placeholder="请输入图纸号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="生产产品名称" prop="gongxuName">
        <el-input v-model="queryParams.gongxuName" placeholder="请输入生产产品名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="生产产品型号" prop="gongxuModel">
        <el-input v-model="queryParams.gongxuModel" placeholder="请输入生产产品型号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!--<el-form-item label="是否自制" prop="isdo">
        <el-select v-model="queryParams.isdo" placeholder="是否自制" clearable style="width: 130px">
          <el-option v-for="dict in dict.type.isdo"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>-->
      <el-form-item label="车间" prop="deptName">
        <el-select v-model="queryParams.deptName" placeholder="请选择车间" style="width: 100%" @change="handshopChange" clearable>
          <el-option v-for="(item, index) in workshopOptions" :key="index" :label="item.label" :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="分配人" prop="updateBy">
        <el-input v-model="queryParams.updateBy" placeholder="请输分配人" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="任务分配状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="任务分配状态" clearable style="width: 130px">
          <el-option v-for="dict in dict.type.task_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <!--<el-button type="warning" plain icon="el-icon-download" size="mini"
                   @click="handleExportDetail" >导出
        </el-button>-->
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
      :max-height="tableMaxHeight">
      <el-table-column align="center" label="序号" type="index" width="50">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable label="生产单号" align="center" prop="produceNo" />
      <el-table-column sortable label="订单编号" align="center" prop="projectNo" show-overflow-tooltip />
      <!-- <el-table-column label="工程名称" align="center" prop="gongchengName" />-->
      <!--<el-table-column align="center" label="合同交货日期"  prop="deliveryTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>-->
      <el-table-column sortable label="产品编码" align="center" prop="goodsCode" />
      <el-table-column sortable label="任务分配状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.task_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="产品名称" prop="goodsName" show-overflow-tooltip />
      <el-table-column sortable align="center" label="产品型号" prop="goodModel" />
      <<!--el-table-column sortable label="工艺名称" align="center" prop="gongyiName" />
      <el-table-column sortable label="工序编码" align="center" prop="code" show-overflow-tooltip />-->
     <!-- <el-table-column sortable label="工序名称" align="center" prop="name" />-->
      <el-table-column sortable align="center"  label="工序名称" prop="name">
        <template slot-scope="scope">
          <el-tooltip class="item" content="点击查看详情" effect="dark" placement="left-start">
            <span @click="showDetailGongxuUser(scope.row)" style="color: #00afff;cursor:pointer;">
              {{scope.row.name}}</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="是否最后一道工序" prop="islast" >
        <template slot-scope="scope" >
          <dict-tag :options="dict.type.yes_no" :value="scope.row.islast"/>
        </template>
      </el-table-column>
      <el-table-column sortable align="center" label="分配人" prop="updateBy" />
      <el-table-column align="center" label="车间" prop="deptName" show-overflow-tooltip />
      <el-table-column align="center" label="标准工时" prop="workHour" show-overflow-tooltip />
      <el-table-column sortable label="生产产品名称" align="center" prop="gongxuName" />
      <el-table-column sortable label="生产产品型号" align="center" prop="gongxuModel" />
      <el-table-column sortable label="单价" align="center" prop="money" />
      <el-table-column sortable label="总数量" align="center" prop="counts" />
      <el-table-column sortable label="已分配数量" align="center" prop="fenpeiCount" />
      <!-- <el-table-column sortable label="剩余分配数量" align="center" prop="remainCount" />-->
      <el-table-column sortable label="已完成数量" align="center" prop="finishCount" />
      <el-table-column sortable label="剩余完成数量" align="center" prop="remainfinishCount" />
      <el-table-column align="center" label="图纸号" prop="shuoming" show-overflow-tooltip />
      <el-table-column align="center" label="产品备注" prop="remark" show-overflow-tooltip />

    </el-table>

    <shengchanDoGongxuUser-form @ok="getList" ref="shengchanDoGongxuUserForm"></shengchanDoGongxuUser-form>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

  </el-dialog>
</template>

<script>
  import {
    deleteAction,
    getAction
  } from '@/api/manage'
  import ShengchanDoGongxuUserForm from '@/views/develop/goodsSale/module/ShengchanDoGongxuUserForm.vue';

  export default {
    name: "ShengchanDoGongxuForm",
    dicts: ['isdo', 'task_status', 'yes_no'],
    components: {
      ShengchanDoGongxuUserForm,
    },
    data() {
      return {
        title: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售产品物料选用明细表格数据
        dataList: [],
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          params: {},
          id: null,
          code: null,
          name: null,
          shuoming: null,
          produceNo: null,
          projectNo: null,
          gongchengName: null,
          goodsName: null,
          goodsCode: null,
          goodModel: null,
          gongxuName:null,
          gongxuModel:null,
          model: null,
          brand: null,
          status: null,
          remark: null,
          projectId: null,
          updateBy: null,
          deptName: null,
          //deptId: this.$store.getters.deptId,
          //deptName: this.$store.getters.deptName,
          orderByColumn: "create_time",
          isAsc: "desc",
        },
        url: {
          list: '/goodsSaledoGongxu/goodsSaledoGongxu/listSaleProFinish',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      showDetailGongxuUser(row){
        this.$refs.shengchanDoGongxuUserForm.show(row);
      },
      show(row) {
        this.open = true;
        this.title = "产品查看";
        this.queryParams.saleId = row.id;
        //this.queryParams.saleId = row.goodsSaleId;
        // this.queryParams.goodsId = row.goodsId;
        // this.queryParams.goodsCode = row.materialsCode;
        // this.queryParams.projectCode = row.ipoNo;
        this.getList();
      },
      /** 查询销售产品物料选用明细列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
    }
  };
</script>
